package com.ewhl.mark.nss;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.animation.Animation;
import com.baidu.mapapi.animation.Transformation;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration.LocationMode;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.bumptech.glide.Glide;
import com.ewhl.mark.nss.net.NetValues;
import com.ewhl.mark.nss.net.UserInfo;
import com.ewhl.mark.nss.net.UserInfob;
import com.ewhl.mark.nss.utils.CommonUtils;
import com.ewhl.mark.nss.utils.SPUtils;
import com.ewhl.mark.nss.volley.BaseVO;
import com.ewhl.mark.nss.volley.GsonRequest;
import com.ewhl.mark.nss.volley.MyErrorListener;
import com.ewhl.mark.nss.volley.MyReponseListener;
import com.zhy.autolayout.AutoLinearLayout;
import com.zhy.autolayout.AutoRelativeLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;

/**
 * 此demo用来展示如何结合定位SDK实现定位，并使用MyLocationOverlay绘制定位位置 同时展示如何使用自定义图标绘制并点击时弹出泡泡
 */
public class CommenMapActivity extends Activity implements SensorEventListener {

    private static final int REQ_CALL_PERMISSION = 111;
    // 定位相关
    LocationClient mLocClient;
    public MyLocationListenner myListener = new MyLocationListenner();
    @BindView(R.id.bmapView)
    MapView mMapView;
    @BindView(R.id.return_iv)
    AutoRelativeLayout returnIv;
    @BindView(R.id.title_tv)
    TextView titleTv;
    @BindView(R.id.get_set)
    AutoRelativeLayout getSet;
    @BindView(R.id.header)
    AutoRelativeLayout header;
    @BindView(R.id.iv_header)
    CircleImageView ivHeader;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.iv_role)
    ImageView ivRole;
    @BindView(R.id.btn_care)
    TextView btnCare;
    @BindView(R.id.tv_tip1)
    TextView tvTip1;
    @BindView(R.id.tv_hint1)
    TextView tvHint1;
    @BindView(R.id.tv_tip2)
    TextView tvTip2;
    @BindView(R.id.tv_hint2)
    TextView tvHint2;
    @BindView(R.id.tv_tip3)
    TextView tvTip3;
    @BindView(R.id.tv_hint3)
    TextView tvHint3;
    @BindView(R.id.ll_extr)
    AutoLinearLayout llExtr;
    @BindView(R.id.tv_details)
    TextView tvDetails;
    @BindView(R.id.ll_detail)
    AutoLinearLayout llDetail;
    @BindView(R.id.btn_call)
    TextView btnCall;
    @BindView(R.id.rl_info)
    AutoLinearLayout rlInfo;
    @BindView(R.id.btn_fabu)
    AutoRelativeLayout btnFabu;
    @BindView(R.id.tv_fabu)
    TextView tvFabu;
    private LocationMode mCurrentMode;
    BitmapDescriptor mCurrentMarker;
    private static final int accuracyCircleFillColor = 0xAAFFFF88;
    private static final int accuracyCircleStrokeColor = 0xAA00FF00;
    private SensorManager mSensorManager;
    private Double lastX = 0.0;
    private int mCurrentDirection = 0;
    private double mCurrentLat = 0.0;
    private double mCurrentLon = 0.0;
    private float mCurrentAccracy;

    List<MapBean.DataBean> mapBeans = new ArrayList<>();
    BaiduMap mBaiduMap;
    NetValues netValues;
    // UI相关
    OnCheckedChangeListener radioButtonListener;
    boolean isFirstLoc = true; // 是否首次定位
    private MyLocationData locData;

    private float direction;
    LatLng northeast;
    LatLng southwest;
    private Point mScreenCenterPoint;
    private int flag = 1;
    private String scid = "-1";
    String currentel;
    int type = 1;
    int role=0;
    Context context;
    String commenurl="http://www.nongshengsheng.com";
    // 初始化全局 bitmap 信息，不用时及时 recycle
    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_location);
        ButterKnife.bind(this);
        context=this;
        mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);//获取传感器管理服务
        mCurrentMode = LocationMode.NORMAL;
        netValues = NetValues.getInstance(this);
        type = getIntent().getIntExtra("type", -1);
        role = getIntent().getIntExtra("role", -1);

        if(type==1){
            titleTv.setText("农机帮");
            if(role==1){
                btnFabu.setVisibility(View.VISIBLE);
                btnFabu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/FarmMachinery/release_task");
                    }
                });

            }else {
                btnFabu.setVisibility(View.GONE);
            }
        }else {
            titleTv.setText("菜价比对");
            Toast.makeText(context, "ROLE"+role, Toast.LENGTH_SHORT).show();
            if(role==1){
                tvFabu.setText("发布菜品");
                btnFabu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/VegetablePrices/release_task_farmer");
                    }
                });
            }else {
                tvFabu.setText("发布需求");
                btnFabu.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/VegetablePrices/release_task_seller");
                    }
                });
            }
        }
        mBaiduMap = mMapView.getMap();
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
        // 定位初始化
        mLocClient = new LocationClient(this);
        mLocClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开gps
        option.setCoorType("bd09ll"); // 设置坐标类型
        option.setScanSpan(1000);
        mLocClient.setLocOption(option);

        mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                rlInfo.setVisibility(View.GONE);
                MapBean.DataBean listBean = (MapBean.DataBean) marker.getExtraInfo().getSerializable("BEAN");

                netValues.get_user_info(listBean.getUser_id(), listBean.getRole(), type, (String) SPUtils.get(CommenMapActivity.this, "key", ""), new MyReponseListener() {


                    @Override
                    public void onResponse(BaseVO arg0) {
                        rlInfo.setVisibility(View.VISIBLE);
                        if(type==1){
                            UserInfo shopInfo = (UserInfo) arg0;
                            if (shopInfo.getStatus() == 1) {
                                try {

                                    takeview(shopInfo);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }else {
                            UserInfob shopInfo = (UserInfob) arg0;
                            if (shopInfo.getStatus() == 1) {

                                try {

                                    takeview(shopInfo);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        }


                    }
                }, new MyErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(CommenMapActivity.this, "error"+error.getMessage(), Toast.LENGTH_SHORT).show();
                        Log.d("err",error.getMessage());
                        super.onErrorResponse(error);
                    }
                });
                return true;
            }
        });
        List<Marker> markers = mBaiduMap.getMarkersInBounds(mBaiduMap.getMapStatus().bound);
        mLocClient.start();
    }

    @Override
    public void onBackPressed() {

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        return false;
    }

    private void takeview(final UserInfo shopInfo) {
        llExtr.setVisibility(View.VISIBLE);


            Glide.with(this).load(Uri.parse(shopInfo.getFm_info().getHead_pic())).into(ivHeader);
            tvName.setText(shopInfo.getFm_info().getName());
            currentel=shopInfo.getFm_info().getPhone();
        btnCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                call(currentel);
            }
        });
            switch (shopInfo.getFm_info().getRole_id()) {
                case "1":
                    ivRole.setImageResource(R.mipmap.icon_employers);
                    tvTip1.setText("需要机型");
                    tvTip2.setText("工作地点");
                    tvHint1.setText(shopInfo.getFm_info().getTask_machine());
                    tvHint2.setText(shopInfo.getFm_info().getTask_address());
                    llExtr.setVisibility(View.GONE);
                    tvDetails.setText(shopInfo.getFm_info().getTask_remark());
                    llDetail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/FarmMachinery/detail_employer/id/"+shopInfo.getFm_info().getId());
                        }
                    });
                    break;
                case "2":

                    ivRole.setImageResource(R.mipmap.icon_owner);
                    tvTip1.setText("提供机型");
                    tvTip2.setText("工作地点");
                    tvTip3.setText("供应价格");
                    tvHint1.setText(shopInfo.getFm_info().getMachine());
                    tvHint2.setText(shopInfo.getFm_info().getWork_address());
                    tvHint3.setText(shopInfo.getFm_info().getWork_price());
                    tvDetails.setText(shopInfo.getFm_info().getRemark());
                    llDetail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/FarmMachinery/detail_machine_owner/id/"+shopInfo.getFm_info().getId());
                        }
                    });
                    break;
                case "3":

                    ivRole.setImageResource(R.mipmap.icon_am);
                    tvTip1.setText("帮忙农活");
                    tvTip2.setText("工作地点");
                    tvTip3.setText("供应价格");

                    tvHint1.setText(shopInfo.getFm_info().getWork_type());
                    tvHint2.setText(shopInfo.getFm_info().getWork_address());
                    tvHint3.setText(shopInfo.getFm_info().getWork_price());
                    tvDetails.setText(shopInfo.getFm_info().getRemark());
                    llDetail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/FarmMachinery/detail_farmer/id/"+shopInfo.getFm_info().getId());
                        }
                    });
                    break;
            }


    }
    private void takeview(final UserInfob shopInfo) {
        llExtr.setVisibility(View.VISIBLE);
        Toast.makeText(this, "type"+type, Toast.LENGTH_SHORT).show();

            Glide.with(this).load(Uri.parse(shopInfo.getVp_info().getHead_pic())).into(ivHeader);
            tvHint1.setText(shopInfo.getVp_info().getVp_category());
            tvName.setText(shopInfo.getVp_info().getName());
            currentel=shopInfo.getVp_info().getPhone();
        btnCall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                call(currentel);
            }
        });
            switch (shopInfo.getVp_info().getRole_id()) {
                case "1":

                    ivRole.setImageResource(R.mipmap.icon_food);
                    tvTip1.setText("供应菜品");
                    tvTip2.setText("供应地点");
                    tvTip3.setText("供应价格");
                    tvHint2.setText(shopInfo.getVp_info().getSupply_address());
                    tvHint3.setText(shopInfo.getVp_info().getVegetable_price());
                    tvDetails.setText(shopInfo.getVp_info().getSupply_remark());
                    llDetail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/VegetablePrices/detail_farmer/id/"+shopInfo.getVp_info().getId());
                        }
                    });

                    break;
                case "2":
                    ivRole.setImageResource(R.mipmap.icon_greengrocer);
                    tvTip1.setText("需求菜品");
                    tvTip2.setText("需求地点");
                    tvTip3.setText("需求数量");
                    tvHint2.setText(shopInfo.getVp_info().getDemand_address());
                    tvHint3.setText(shopInfo.getVp_info().getQuantity());
                    tvDetails.setText(shopInfo.getVp_info().getDemand_remark());
                    llDetail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/VegetablePrices/detail_seller/id/"+shopInfo.getVp_info().getId());
                        }
                    });
                    break;

        }


    }

    private void call(String phone) {
        if(CommonUtils.checkNull(phone)){
            Uri uri = Uri.parse("tel:");
            Intent intent = new Intent(Intent.ACTION_CALL, uri);
            if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, REQ_CALL_PERMISSION);
                return;
            }
            startActivity(intent);
        }else {
            Toast.makeText(context, "该用户暂未设置号码", Toast.LENGTH_SHORT).show();
        }
    }
    @SuppressLint("MissingPermission")
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case REQ_CALL_PERMISSION:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    Uri uri = Uri.parse("tel:"+currentel);
                    Intent intent = new Intent(Intent.ACTION_CALL, uri);
                    startActivity(intent);
                } else {
                    Toast.makeText(this, "请先开启打电话权限", Toast.LENGTH_LONG).show();
                }
                break;
        }
    }

    @Override
    public void onSensorChanged(SensorEvent sensorEvent) {
        double x = sensorEvent.values[SensorManager.DATA_X];
        if (Math.abs(x - lastX) > 1.0) {
            mCurrentDirection = (int) x;
            locData = new MyLocationData.Builder()
                    .accuracy(mCurrentAccracy)
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(mCurrentDirection).latitude(mCurrentLat)
                    .longitude(mCurrentLon).build();
            mBaiduMap.setMyLocationData(locData);
        }
        lastX = x;

    }

    public void initOverlay(String ne, String sw) {
        // add marker overlay

        netValues.get_near_list(type, ne, sw, new MyReponseListener() {
            @Override
            public void onResponse(BaseVO arg0) {
                MapBean bean = (MapBean) arg0;
//                    try {
                if (bean.getStatus() == 1) {
                    if (mapBeans.size() > 0 && list_equl(mapBeans, bean.getData())) {
                        return;
                    }
                    mapBeans = bean.getData();
                    mBaiduMap.clear();

                    for (MapBean.DataBean item_bean : mapBeans) {
                        LatLng latLng = new LatLng(item_bean.getLatitude(), item_bean.getLongitude());
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("BEAN", item_bean);
                        View view = View.inflate(getApplicationContext(), R.layout.item_bean, null);
                        ImageView maker = (ImageView) view.findViewById(R.id.marker);
                        if (type == 1) {
                            switch (item_bean.getRole()) {
                                case 1:
                                    maker.setImageResource(R.mipmap.nav_farmers);
                                    break;
                                case 2:
                                    maker.setImageResource(R.mipmap.nav_machinery);
                                    break;
                                case 3:
                                    maker.setImageResource(R.mipmap.nav_tools);
                                    break;
                            }
                        } else {
                            switch (item_bean.getRole()) {
                                case 2:
                                    maker.setImageResource(R.mipmap.nav_greengrocer);
                                    break;
                                case 1:
                                    maker.setImageResource(R.mipmap.nav_food);
                                    break;
                            }
                        }
                        //将View转化为Bitmap
                        BitmapDescriptor descriptor = BitmapDescriptorFactory.fromView(view);
                        OverlayOptions options = new MarkerOptions().position(latLng).icon(descriptor).extraInfo(bundle).zIndex(9).draggable(true);
                        Marker marker = (Marker) mBaiduMap.addOverlay(options);
                        startTransformation(marker, latLng);
                    }
                } else {

                }

//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
            }
        }, new MyErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                super.onErrorResponse(error);
            }
        });


//        MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(12.0f);
//        mBaiduMap.setMapStatus(msu);

    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int i) {

    }

    public void startTransformation(Marker markerOptions, LatLng latLng) {
        try {
            markerOptions.setAnimation(getTransformation(latLng));
            markerOptions.startAnimation();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private Animation getTransformation(LatLng llC) {
        Point point = mBaiduMap.getProjection().toScreenLocation(llC);
        LatLng latLng1 = mBaiduMap.getProjection().fromScreenLocation(new Point(point.x, point.y - 100));
        Transformation mTransforma = new Transformation(llC, latLng1, llC);
        mTransforma.setDuration(500);
        mTransforma.setRepeatMode(Animation.RepeatMode.RESTART);//动画重复模式
        mTransforma.setRepeatCount(1);//动画重复次数
        mTransforma.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart() {
            }

            @Override
            public void onAnimationEnd() {

            }

            @Override
            public void onAnimationCancel() {
            }

            @Override
            public void onAnimationRepeat() {

            }
        });

        return mTransforma;
    }

    boolean list_equl(List a, List b) {
        if (a.size() != b.size()) {
            return false;
        }

        for (int i = 0; i < a.size(); i++) {
            if (!a.get(i).equals(b.get(i))) {
                return false;
            }
        }
        return true;
    }

    @OnClick({R.id.return_iv, R.id.get_set, R.id.btn_care, R.id.btn_call, R.id.btn_fabu})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.return_iv:
                Intent it=new Intent(context,MainActivity.class);
                it.putExtra("load_url",commenurl+"/index.php/mobile/index/index");
                it.setFlags(  Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                context.startActivity(it);
                finish();
                break;
            case R.id.get_set:
                if (type==1){
                    CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/FarmMachinery/user_info/token/"+SPUtils.get(context,"key","")+"/role/"+role);
                }else {
                    CommonUtils.goToWeb(context,MainActivity.class,commenurl+"/index.php/Mobile/VegetablePrices/user_info/token/"+SPUtils.get(context,"key","")+"/role/"+role);
                }
                break;
            case R.id.btn_care:
                break;
            case R.id.btn_call:
                break;
            case R.id.btn_fabu:
                break;
        }
    }

    /**
     * 定位SDK监听函数
     */
    public class MyLocationListenner implements BDLocationListener {

        @Override
        public void onReceiveLocation(BDLocation location) {
            // map view 销毁后不在处理新接收的位置
            if (location == null || mMapView == null) {
                return;
            }
            mCurrentLat = location.getLatitude();
            mCurrentLon = location.getLongitude();
            mCurrentAccracy = location.getRadius();
            locData = new MyLocationData.Builder()
                    .accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(mCurrentDirection).latitude(location.getLatitude())
                    .longitude(location.getLongitude()).build();
            mBaiduMap.setMyLocationData(locData);
            if (isFirstLoc) {
                isFirstLoc = false;
                LatLng ll = new LatLng(location.getLatitude(),
                        location.getLongitude());
                MapStatus.Builder builder = new MapStatus.Builder();
                builder.target(ll).zoom(16.5f);
                mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
                northeast = mBaiduMap.getMapStatus().bound.northeast;
                southwest = mBaiduMap.getMapStatus().bound.southwest;
                initOverlay(northeast.longitude + "," + northeast.latitude, southwest.longitude + "," + southwest.latitude);


                mBaiduMap.setOnMapRenderCallbadk(new BaiduMap.OnMapRenderCallback() {
                    @Override
                    public void onMapRenderFinished() {


                        northeast = mBaiduMap.getMapStatus().bound.northeast;
                        southwest = mBaiduMap.getMapStatus().bound.southwest;
                        initOverlay(northeast.longitude + "," + northeast.latitude, southwest.longitude + "," + southwest.latitude);

                        Log.d("srgslocation", "ne:" + northeast.latitude + "-----" + northeast.longitude);
                        Log.d("srgslocation", "sw:" + southwest.latitude + "-----" + southwest.longitude);

                    }
                });
                mBaiduMap.setOnMapTouchListener(new BaiduMap.OnMapTouchListener() {
                    @Override
                    public void onTouch(MotionEvent motionEvent) {
                            if(motionEvent.getAction()==MotionEvent.ACTION_MOVE){
                                rlInfo.setVisibility(View.GONE);
                            }
                    }
                });
            }


        }

        public void onReceivePoi(BDLocation poiLocation) {
        }
    }

    @Override
    protected void onPause() {
        mMapView.onPause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        mMapView.onResume();
        super.onResume();
        //为系统的方向传感器注册监听器
        mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
                SensorManager.SENSOR_DELAY_UI);
    }

    @Override
    protected void onStop() {
        //取消注册传感器监听
        mSensorManager.unregisterListener(this);
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        // 退出时销毁定位
        mLocClient.stop();
        // 关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        mMapView.onDestroy();
        mMapView = null;
        super.onDestroy();
    }


}
